home *** CD-ROM | disk | FTP | other *** search
- Path: news.rain.org!usenet
- From: "Guus Leeuw jr." <guusl@eiffel.com>
- Newsgroups: comp.lang.c
- Subject: Re: system() & error detection
- Date: Fri, 01 Mar 1996 08:41:27 -0800
- Organization: Interactive Software Engineering Inc. http://www.eiffel.com/
- Message-ID: <313728B7.2112A121@eiffel.com>
- References: <4gt24g$dba@ncar.ucar.edu>
- NNTP-Posting-Host: @outback.eiffel.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i586)
- CC: jadams@sage.cgd.ucar.edu
-
- James Adams wrote:
- >
- > Hello,
- >
- > I am attempting to use the system() call in order to have a
- > user-specified command execute in my program.
- >
- > I am wondering how I can check whether or not the command has
- > completed successfully ? I don't want the program to continue if the
- > call I make from system() produces some sort of error. I'd like to be
- > able to do something like the following:
- >
- > result = system(command);
- > if (result == ERROR)
- > exit(0);
- >
- > Is there anyway to do this ? Should I be using something other than
- > system() ?
-
- According to the standard (references are listed with FAQ 19.27),
- system() will return -1 upon execution error. Any other value is the
- return code of the called program.
-
- With execution error is meant that system() cannot perform the task
- asked for.
-
- The return code of the called program is what you return from main().
- For examples `int main(){ return 1; }. The value 1 is the return code.
- The caller of this little program has to know how to interpret the
- returned value.
-
- Hope this helps,
- Guus
-